package com.wanghui.core.module.test;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext;

/**
 * web服务器测试工具
 * @author Xredman
 * Oct 16, 2011
 */
public class ServerUtils {

	public static Server buildNormalServer(int port, String contextPath){
		Server server = new Server(port);
		WebAppContext webContext = new WebAppContext("src/main/webapp", contextPath);
		webContext.setClassLoader(Thread.currentThread().getContextClassLoader());
		server.setHandler(webContext);
		server.setStopAtShutdown(true);
		return server;
	}
	
	public static Server buildTestServer(int port, String contextPath){
		Server server = buildNormalServer(port, contextPath);
		((WebAppContext)server.getHandler()).setDescriptor("src/test/resources/web.xml");
		return server;
	}
}
